#include <stdio.h>
#include <signal.h>
#include <unistd.h>


void hande(int sig)
{
	printf("信号捕获到了sig\n");
	if(sig == SIGINT)
	{
		printf("捕获到了SIGINT的信号\n");

	}else if(sig == SIGALRM)
	{
		printf("捕获到了SIGALRM\n");
		alarm(1);
	}
}

//sigaction使用
int main()
{

	struct sigaction act;		//先定义sigaction

	act.sa_handler = hande;		//初始化sigaction
	act.sa_flags = 0;
	sigfillset(&act.sa_mask);

	//捕获sigint信号
	sigaction(SIGINT, &act, NULL);	//使用sigaction

	alarm(1);

	//捕获SIGALRM信号
	sigaction(SIGALRM, &act, NULL);

	while(1)
	{
		sleep(1);
	}

}









